<?php 
include 'jssdk.php'; 
$jssdk=new JSSDK("xxx","xxx");
$signPackage=$jssdk->getSignPackage();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>图片上传</title>
<!-- 引入 WeUI -->
<link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/1.1.3/weui.min.css"/>
<script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js" type="text/javascript"></script>
<script src="zepto.js" type="text/javascript"></script>
<script src="up.js" type="text/javascript"></script>
</head>
<body>
<form onSubmit="return submsg(this);">
<!-- 使用 -->
<img src="/static/images/lanmu.jpg" style="width:100%" />
<div class="weui-cell">
  <div class="weui-cell__hd"></div>
  <div class="weui-cell__bd">
    <h2 style="text-align:center;color:#aa2628">上专</h2>
    
    <div class="weui-cells">
      <div class="weui-cell">
        <div class="weui-cell__bd">
          <input class="weui-input" type="text" placeholder="输入标题" name="title" id="title"/>
        </div>
      </div>
    </div>
     
    <div class="weui-cells weui-cells_form">
      <div class="weui-cell">
        <div class="weui-cell__bd">
          <textarea class="weui-textarea" placeholder="输入内容（可选）" rows="3" name="content" id="content"></textarea>
		  
          <div class="weui-textarea-counter"><span>0</span>/200</div>
        </div>
      </div>
    </div>
  </div>
</div>
<div id="loadingToast" style="display:none;">
    <div class="weui-mask_transparent"></div>
    <div class="weui-toast">
        <i class="weui-loading weui-icon_toast"></i>
        <p class="weui-toast__content">数据加载中</p>
    </div>
</div>
<div class="weui-cell">
  <div class="weui-cell__hd"></div>
  <div class="weui-cell__bd">
    <div class="weui-uploader">
      <div class="weui-uploader__hd">
        <p class="weui-uploader__title" style="color: #3d4145;">图片</p>
        <div class="weui-uploader__info"><span id="already_upload">0</span>/4</div>
      </div>
      <div class="weui-uploader__bd" style="overflow: inherit">
        <ul class="weui-uploader__files" id="uploaderFiles">
        </ul>
        <div class="weui-uploader__input-box"> <span id="uploaderInput" class="weui-uploader__input"></span> </div>
      </div>
    </div>
  </div>
</div>
<button type="submit" class="weui-btn weui-btn_primary" style="margin-top:50px;">提交</button>
</form>
<script> 
$(()=>{

  //注册js sdk 配置
	wx.config({
		debug: false,
		appId: '<?php echo $signPackage["appId"];?>',
		timestamp: <?php echo $signPackage["timestamp"];?>,
		nonceStr: '<?php echo $signPackage["nonceStr"];?>',
		signature: '<?php echo $signPackage["signature"];?>',
		jsApiList: [
			"chooseImage", "uploadImage", "downloadImage", "previewImage"
		]
	});
});

wx.ready(function () {
	// 1 判断当前版本是否支持指定 JS 接口，支持批量判断
	wx.checkJsApi({
		jsApiList: [
			'chooseImage',
			'previewImage',
			'uploadImage',
			'downloadImage'
		],
		success: function (res) {
			//alert(JSON.stringify(res));
			if (res.checkResult.getLocation == false) {
				alert('你的微信版本太低，不支持微信JS接口，请升级到最新的微信版本！');
				return;
			} else {
				$("#uploaderInput").click(function () {
					wxChooseImage();
				})
			}
		},
		error: function (res) {
			alert(JSON.stringify("error=" + res));
		}
	});
});



 
//ajax提交留言 
function submsg(obj){ 
  var url='/savemsg.php';  
  var title=$(obj).find("#title").val();
  var content=$(obj).find("#content").val();
  var pics="";  
  $("#uploaderFiles").find("input").each(function(){
  	pics+=$(this).val()+";";
  });
  var mdate=getDatestr();
  var uper=getCookie("username");
  var checkcode="";
  
  $.ajax({
    type: 'POST',
    url: url,
    dataType: 'json',
    data: {
        title: title,
        content: content,
        pics: pics,
        mdate:mdate,
        uper:uper,
        checkcode: checkcode
    },
    success: function (response, status) {
      if(response.code){
         alert("已提交！");
         window.location.href="/";
      }else{
         alert(response.data);
      }
    },
    error:function(xhr,status,error){
      alert('提交失败，请联系管理员！');
    }
  });
  return false;
}



</script>

</body>
</html>
